﻿//===============================================================================
// Microsoft Innovation Centre - Western Europe
// Copyright (c) 2008 Microsoft Corporation. All rights reserved.
//
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================
// The example companies, organizations, products, domain names,
// e-mail addresses, logos, people, places, and events depicted
// herein are fictitious.  No association with any real company,
// organization, product, domain name, email address, logo, person,
// places, or events is intended or should be inferred.
//===============================================================================

using System;
using Microsoft.WVB.Framework;
using Microsoft.WVB.Framework.Entities;

namespace Microsoft.WVB.Services
{
    public static partial class EntityConverter
    {
        public static MembershipUser ConvertToMemberhipUser(MicMembershipService.WVBUser serviceUser)
        {
            MembershipUser user = null;

            if (serviceUser != null)
            {
                user = new MembershipUser();
                user.Email = serviceUser.Email;
                user.ProviderName = serviceUser.ProviderName;
                user.UserName = serviceUser.UserName;
            }
            return user;
        }

        public static MicMembershipService.WVBUser ConvertToWVBUser(MembershipUser user)
        {
            MicMembershipService.WVBUser serviceUser = null;

            if (user != null)
            {
                serviceUser = new MicMembershipService.WVBUser();
                serviceUser.Email = user.Email;
                serviceUser.ProviderName = user.ProviderName;
                serviceUser.UserName = user.UserName;
            }
            return serviceUser;
        }


        internal static ProfileInfo ConvertToProfileInfo(MicProfileService.WVBProfile wvbProfile)
        {
            ProfileInfo profile = null;

            if (wvbProfile != null)
            {
                profile = new ProfileInfo(wvbProfile.Username);
                profile.BirthDate = wvbProfile.BirthDate;
                profile.CompanySize = wvbProfile.CompanySize;
                profile.Country = wvbProfile.Country;
                profile.FirstName = wvbProfile.FirstName;
                profile.Gender = (Gender) Enum.Parse(typeof(Gender), wvbProfile.Gender.ToString(), true);
                profile.Income = wvbProfile.Income;
                profile.Industry = wvbProfile.Industry;
                profile.Interests = wvbProfile.Interests;
                profile.JobTitle = wvbProfile.JobTitle;
                profile.LastName = wvbProfile.LastName;
                profile.Level = (ProfileLevel)Enum.Parse(typeof(ProfileLevel), wvbProfile.Level.ToString(), true);
                profile.ZipCode = wvbProfile.ZipCode;
            }

            return profile;

        }

        internal static MicProfileService.WVBProfile ConvertToWVBProfile(ProfileInfo profile)
        {
            MicProfileService.WVBProfile shProfile = null;
            if (profile != null)
            {
                shProfile = new Microsoft.WVB.Services.MicProfileService.WVBProfile();
                shProfile.BirthDate = profile.BirthDate ?? default(DateTime);
                shProfile.CompanySize = profile.CompanySize ?? -1;
                shProfile.Country = profile.Country;
                shProfile.FirstName = profile.FirstName;
                shProfile.Gender = (MicProfileService.Gender) Enum.Parse(typeof(MicProfileService.Gender), profile.Gender.ToString(), true);
                shProfile.Income = profile.Income ?? -1;
                shProfile.Industry = profile.Industry;
                shProfile.Interests = profile.Interests;
                shProfile.JobTitle = profile.JobTitle;
                shProfile.LastName = profile.LastName;
                shProfile.Level = (MicProfileService.ProfileLevel)Enum.Parse(typeof(MicProfileService.ProfileLevel), profile.Level.ToString(), true);
                shProfile.Username = profile.Username;
                shProfile.ZipCode =  profile.ZipCode ?? -1;
            }

            return shProfile;
        }
    }
}
